package controller;

import pojo.User;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * @author: zen
 * @date: 2020/4/19
 * @Title: secretCheck
 * @Description:
 */

@WebServlet("/secretCheck")
public class SecretCheck extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.setContentType("text/html;charset=utf-8");
        HttpSession session = req.getSession();
        PrintWriter out = resp.getWriter();
        User user = (User) session.getAttribute("user");
        String secret = req.getParameter("pass");
        if (user == null) {
            out.write("error");
            out.flush();
            out.close();
            return;
        }
        if (secret.equals(user.getPass())) {
            out.write("ok");
        }
        out.flush();
        out.close();
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
